<html>
<head><meta charset="utf-8"><title>transmute::&lt;f32, u32&gt; · t-lang/wg-unsafe-code-guidelines · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/index.html">t-lang/wg-unsafe-code-guidelines</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/transmute.3A.3A.3Cf32.2C.20u32.3E.html">transmute::&lt;f32, u32&gt;</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="162199075"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/transmute%3A%3A%3Cf32%2C%20u32%3E/near/162199075" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/transmute.3A.3A.3Cf32.2C.20u32.3E.html#162199075">(Apr 01 2019 at 00:23)</a>:</h4>
<p>I am almost afraid to ask, but...</p>



<a name="162199130"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/transmute%3A%3A%3Cf32%2C%20u32%3E/near/162199130" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/transmute.3A.3A.3Cf32.2C.20u32.3E.html#162199130">(Apr 01 2019 at 00:24)</a>:</h4>
<p><code>f32::from_bits</code> is cool</p>



<a name="162199131"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/transmute%3A%3A%3Cf32%2C%20u32%3E/near/162199131" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/transmute.3A.3A.3Cf32.2C.20u32.3E.html#162199131">(Apr 01 2019 at 00:24)</a>:</h4>
<p>what's the deal with the other direction?</p>



<a name="162199143"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/transmute%3A%3A%3Cf32%2C%20u32%3E/near/162199143" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/transmute.3A.3A.3Cf32.2C.20u32.3E.html#162199143">(Apr 01 2019 at 00:24)</a>:</h4>
<p>these sorts of <code>f32</code> &lt;-&gt; <code>u32</code> hacks seem super useful in making approximations of all sorts of arithmetic operations</p>



<a name="162199278"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/transmute%3A%3A%3Cf32%2C%20u32%3E/near/162199278" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/transmute.3A.3A.3Cf32.2C.20u32.3E.html#162199278">(Apr 01 2019 at 00:26)</a>:</h4>
<p>see the "quake invsqrt" or something like <a href="https://bits.stephan-brumme.com/squareRoot.html" target="_blank" title="https://bits.stephan-brumme.com/squareRoot.html">https://bits.stephan-brumme.com/squareRoot.html</a></p>



<a name="162199284"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/transmute%3A%3A%3Cf32%2C%20u32%3E/near/162199284" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/transmute.3A.3A.3Cf32.2C.20u32.3E.html#162199284">(Apr 01 2019 at 00:26)</a>:</h4>
<p>or <a href="https://ieeexplore.ieee.org/document/6375931" target="_blank" title="https://ieeexplore.ieee.org/document/6375931">https://ieeexplore.ieee.org/document/6375931</a></p>



<a name="162199305"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/transmute%3A%3A%3Cf32%2C%20u32%3E/near/162199305" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/transmute.3A.3A.3Cf32.2C.20u32.3E.html#162199305">(Apr 01 2019 at 00:27)</a>:</h4>
<p>but the core idea of all of these is <code>f32</code> -&gt; <code>u32</code> -&gt; [ bit twiddling ] -&gt; <code>u32</code> -&gt; <code>f32</code></p>



<a name="162199309"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/transmute%3A%3A%3Cf32%2C%20u32%3E/near/162199309" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/transmute.3A.3A.3Cf32.2C.20u32.3E.html#162199309">(Apr 01 2019 at 00:27)</a>:</h4>
<p><code>f32::from_bits</code> is useful for the output</p>



<a name="162211890"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/transmute%3A%3A%3Cf32%2C%20u32%3E/near/162211890" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> kennytm <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/transmute.3A.3A.3Cf32.2C.20u32.3E.html#162211890">(Apr 01 2019 at 06:04)</a>:</h4>
<p>What's wrong with <code>f32::to_bits</code>?</p>



<a name="162258956"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/transmute%3A%3A%3Cf32%2C%20u32%3E/near/162258956" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/transmute.3A.3A.3Cf32.2C.20u32.3E.html#162258956">(Apr 01 2019 at 17:16)</a>:</h4>
<p>whoa! it exists! awesome, thanks</p>



<a name="162258969"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/transmute%3A%3A%3Cf32%2C%20u32%3E/near/162258969" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/transmute.3A.3A.3Cf32.2C.20u32.3E.html#162258969">(Apr 01 2019 at 17:16)</a>:</h4>
<p>somehow I overlooked it</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>